home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume6 / cubes2 / part08 < prev   
Encoding:
Internet Message Format  |  1989-07-06  |  43.0 KB

  1. Path: uunet!tektronix!tekgen!tekred!games
  2. From: games@tekred.CNA.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v06i066:  cubes2 - a networked dice game (version 5.1), Part08/08
  5. Message-ID: <3907@tekred.CNA.TEK.COM>
  6. Date: 27 Apr 89 19:24:39 GMT
  7. Sender: billr@tekred.CNA.TEK.COM
  8. Lines: 1590
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: gmp@rayssdb.RAY.COM (Gregory M. Paris)
  12. Posting-number: Volume 6, Issue 66
  13. Archive-name: cubes2/Part08
  14.  
  15.  
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 8 (of 8)."
  24. # Contents:  Makefile avg.c cubeorder.sh cuberank.6 cubes.h
  25. #   cubeserver.6 histconv.sh random.c
  26. # Wrapped by billr@saab on Thu Apr 27 12:13:41 1989
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'Makefile'\"
  30. else
  31. echo shar: Extracting \"'Makefile'\" \(4919 characters\)
  32. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  33. X#! /bin/make -f
  34. X# vi:set sw=4 ts=4:
  35. X
  36. XOWNER=        gdaemon
  37. XGROUP=        games
  38. XGAMEDIR=    /usr/games
  39. XGLIBDIR=    $(GAMEDIR)/lib
  40. XPATHNAME=    $(GLIBDIR)/cubeserver
  41. XHISTFILE=    $(GLIBDIR)/cubes.hist
  42. XMONFILE=    $(GLIBDIR)/cubes.monikers
  43. XMANDIR=        /usr/man/man6
  44. XMANPAGES=    $(MANDIR)/cubes.6 $(MANDIR)/cubes.long.6 \
  45. X            $(MANDIR)/cubestat.6 $(MANDIR)/cuberank.6 \
  46. X            $(MANDIR)/cubeserver.6
  47. X
  48. X# If you want the server and client to use a UNIX domain socket
  49. X# for local connections, define UNIXSOCK here.  It must be a pathname
  50. X# to a file in a directory where OWNER has write permission.
  51. X#
  52. X# If you want the server to open an INET domain socket -- allowing
  53. X# players from remote systems -- then define INETSOCK.  The client
  54. X# INET code is compiled in, whether or not INETSOCK is defined.
  55. X#
  56. X# The server will not run if both UNIXSOCK and INETSOCK are left undefined.
  57. X#
  58. XSOCKETS=    -DUNIXSOCK=\"/usr/tmp/cubesocket\" -DINETSOCK
  59. X#SOCKETS=    -DINETSOCK
  60. X#SOCKETS=    -DUNIXSOCK=\"/usr/tmp/cubesocket\"
  61. X
  62. X# GECOS and LIBGECOS are for special password file gecos field decoding.
  63. X# Defining it works only at the author's locale.
  64. X#GECOS=        -DGECOS
  65. X#LIBGECOS=    -lgecos
  66. XGECOS=
  67. XLIBGECOS=
  68. X
  69. X# if graphics won't work, add -DLONGNAMEBUG to CFLAGS
  70. X# I use -OG on our pyramid
  71. X#CFLAGS=    -OG
  72. XCFLAGS=        -O
  73. XLDFLAGS=
  74. X
  75. XSRVFLAGS=    -DPATHNAME=\"$(PATHNAME)\" -DHISTFILE=\"$(HISTFILE)\" $(SOCKETS)
  76. XCLIFLAGS=    $(SOCKETS)
  77. XHANFLAGS=    -DHISTFILE=\"$(HISTFILE)\"
  78. XMONFLAGS=    -DMONFILE=\"$(MONFILE)\"
  79. X
  80. XLIBS=        -lcurses -ltermcap -lm
  81. X
  82. XSRVOBJS=    cubeserv1.o cubeserv2.o announce.o comptbl.o history.o moniker.o \
  83. X            turn.o risk.o tempers.o strategies.o tactics.o dieopts.o random.o
  84. XCLIOBJS=    cubes.o actions.o screen.o random.o fullname.o
  85. XAVGOBJS=    avg.o dieopts.o random.o
  86. XHSTOBJS=    histanal.o comptbl.o history.o tempers.o strategies.o \
  87. X            random.o fullname.o
  88. XSTTOBJS=    cubestat.o
  89. X
  90. XSRVSRCS=    cubeserv1.c cubeserv2.c announce.c comptbl.c history.c moniker.c \
  91. X            turn.c risk.c tempers.c strategies.c tactics.c dieopts.c random.c
  92. XCLISRCS=    cubes.c actions.c screen.c random.c fullname.c
  93. XAVGSRCS=    avg.c dieopts.c random.c
  94. XHSTSRCS=    histanal.c comptbl.c history.c tempers.c strategies.c \
  95. X            random.c fullname.c
  96. XSTTSRCS=    cubestat.c
  97. X
  98. Xall:        source cubeserver cubes cuberank cubestat avg \
  99. X            cubes.6 cubes.long.6 cubestat.6 cuberank.6 cubeserver.6
  100. Xsource:        $(SRVSRCS) $(CLISRCS) $(AVGSRCS) $(HSTSRCS) $(STTSRCS)
  101. Xbins:        $(GLIBDIR)/cubeserver
  102. Xbins:        $(GAMEDIR)/cubes $(GAMEDIR)/cubestat $(GAMEDIR)/cuberank
  103. Xbins:        $(GAMEDIR)/scr
  104. Xfiles:        $(HISTFILE) $(MONFILE) $(MANPAGES)
  105. Xinstall:    source all bins files
  106. X
  107. X$(GLIBDIR)/cubeserver:    cubeserver
  108. X    install -c -m 4100 -o $(OWNER) -g $(GROUP) cubeserver $(GLIBDIR)
  109. X
  110. X$(GAMEDIR)/cubes:        cubes
  111. X    install -c -m  111 -o $(OWNER) -g $(GROUP) cubes      $(GAMEDIR)
  112. X    install -c -m  111 -o $(OWNER) -g $(GROUP) cubes      $(GAMEDIR)
  113. X
  114. X$(GAMEDIR)/cubestat:    cubestat
  115. X    install -c -m  111 -o $(OWNER) -g $(GROUP) cubestat   $(GAMEDIR)
  116. X
  117. X$(GAMEDIR)/cuberank:    cuberank
  118. X    install -c -m 4111 -o $(OWNER) -g $(GROUP) cuberank   $(GAMEDIR)
  119. X
  120. X$(GAMEDIR)/scr:    scr.sh
  121. X    install -c -m  755 -o $(OWNER) -g $(GROUP) scr.sh     $(GAMEDIR)/scr
  122. X
  123. X
  124. Xcubeserver:    $(SRVOBJS)
  125. X    cc $(LDFLAGS) -o cubeserver $(SRVOBJS) $(LIBS)
  126. X
  127. Xcubes:    $(CLIOBJS)
  128. X    cc $(LDFLAGS) -o cubes $(CLIOBJS) $(LIBS) $(LIBGECOS)
  129. X
  130. Xavg:    $(AVGOBJS)
  131. X    cc $(LDFLAGS) -o avg $(AVGOBJS) $(LIBS)
  132. X
  133. Xhistanal cuberank:    $(HSTOBJS)
  134. X    cc $(LDFLAGS) -o histanal $(HSTOBJS) $(LIBS) $(LIBGECOS)
  135. X    rm -f cuberank ; ln histanal cuberank
  136. X
  137. Xcubestat:    $(STTOBJS)
  138. X    cc $(LDFLAGS) -o cubestat $(STTOBJS)
  139. X
  140. X
  141. Xcubeserv1.o:    cubeserv1.c cubes.h Makefile
  142. X    cc $(CFLAGS) $(SRVFLAGS) -c cubeserv1.c
  143. X
  144. Xcubes.o:    cubes.c cubes.h Makefile
  145. X    cc $(CFLAGS) $(CLIFLAGS) -c cubes.c
  146. X
  147. Xhistanal.o:    histanal.c cubes.h Makefile
  148. X    cc $(CFLAGS) $(HANFLAGS) -c histanal.c
  149. X
  150. Xmoniker.o:    moniker.c cubes.h Makefile
  151. X    cc $(CFLAGS) $(MONFLAGS) -c moniker.c
  152. X
  153. Xfullname.o:    fullname.c cubes.h Makefile
  154. X    cc $(CFLAGS) $(GECOS) -c fullname.c
  155. X
  156. X$(SRVOBJS):    cubes.h
  157. X$(CLIOBJS):    cubes.h
  158. X$(AVGOBJS):    cubes.h
  159. X$(HSTOBJS):    cubes.h
  160. X$(STTOBJS):    cubes.h
  161. X
  162. X
  163. X# we must have a history file, but we need build it only once
  164. X$(HISTFILE):    Makefile
  165. X    touch $(HISTFILE)
  166. X    chown $(OWNER) $(HISTFILE)
  167. X    chgrp $(GROUP) $(HISTFILE)
  168. X    chmod 644 $(HISTFILE)
  169. X
  170. X# we must have a monikers file, but we need build it only once
  171. X$(MONFILE):    Makefile
  172. X    touch $(MONFILE)
  173. X    chown $(OWNER) $(MONFILE)
  174. X    chgrp $(GROUP) $(MONFILE)
  175. X    chmod 644 $(MONFILE)
  176. X
  177. X
  178. X$(MANDIR)/cubes.6:        cubes.6
  179. X    install -c -m 644 cubes.6 $(MANDIR)
  180. X
  181. X$(MANDIR)/cubes.long.6:        cubes.long.6
  182. X    install -c -m 644 cubes.long.6 $(MANDIR)
  183. X
  184. X$(MANDIR)/cubestat.6:    cubestat.6
  185. X    install -c -m 644 cubestat.6 $(MANDIR)
  186. X
  187. X$(MANDIR)/cuberank.6:    cuberank.6
  188. X    install -c -m 644 cuberank.6 $(MANDIR)
  189. X
  190. X$(MANDIR)/cubeserver.6:    cubeserver.6
  191. X    install -c -m 644 cubeserver.6 $(MANDIR)
  192. X
  193. X
  194. Xclean:
  195. X    rm -f *.o cubes cubeserver cuberank histanal cubestat avg cubes.shar*
  196. X
  197. Xnewsdist:
  198. X    makekit -p -s50k -ncubes README cube*.6 Makefile *.[ch] *.sh
  199. X
  200. Xmaildist:
  201. X    shar README cube*.6 Makefile *.[ch] *.sh >cubes.shar
  202. X    package cubes.shar 350
  203. END_OF_FILE
  204. if test 4919 -ne `wc -c <'Makefile'`; then
  205.     echo shar: \"'Makefile'\" unpacked with wrong size!
  206. fi
  207. # end of 'Makefile'
  208. fi
  209. if test -f 'avg.c' -a "${1}" != "-c" ; then 
  210.   echo shar: Will not clobber existing file \"'avg.c'\"
  211. else
  212. echo shar: Extracting \"'avg.c'\" \(5359 characters\)
  213. sed "s/^X//" >'avg.c' <<'END_OF_FILE'
  214. X/*    vi:set sw=4 ts=4: */
  215. X#ifndef    lint
  216. Xstatic char    sccsid[] = "@(#)avg.c 5.1 (G.M. Paris) 89/01/22";
  217. X#endif    lint
  218. X
  219. X/*
  220. X**
  221. X**    cubes 5.1  Copyright 1989 Gregory M. Paris
  222. X**        Permission granted to redistribute on a no charge basis.
  223. X**        All other rights are reserved.
  224. X**
  225. X*/
  226. X
  227. X#include    <stdio.h>
  228. X#include    "cubes.h"
  229. X
  230. Xboolean            jokermode    = False;
  231. X
  232. Xextern int        optind;
  233. Xextern int        opterr;
  234. Xextern char       *optarg;
  235. Xextern long        atol();
  236. X
  237. X#define    ROLLS        1000000L    /* one million trials */
  238. X
  239. Xenum t_c {
  240. X    T_AOK,        /* 5    /* all of a kind */
  241. X    T_STR,        /* 5    /* straight */
  242. X    T_ASMSTR,    /* 5    /* assembled straight */
  243. X    T_4OK1S,    /* 5    /* four of a kind w/ one single */
  244. X    T_SMSTR1S,    /* 5    /* small straight w/ one single */
  245. X    T_3OK2S,    /* 5    /* three of a kind w/ two singles */
  246. X    T_5S,        /* 5    /* five singles */
  247. X    T_4OK,        /* 4    /* four of a kind */
  248. X    T_SMSTR,    /* 4    /* small straight */
  249. X    T_3OK1S,    /* 4    /* three of a kind w/one single */
  250. X    T_4S,        /* 4    /* four singles */
  251. X    T_3OK,        /* 3    /* three of a kind */
  252. X    T_3S,        /* 3    /* three singles */
  253. X    T_2S,        /* 2    /* two singles */
  254. X    T_1S,        /* 1    /* one single */
  255. X    T_ZIP,        /* 0    /* nothing */
  256. X    T_SIZE
  257. X};
  258. X
  259. Xstatic char       *t_name[]    = {
  260. X    "all of a kind",
  261. X    "straight",
  262. X    "assembled straight",
  263. X    "four of a kind w/ one single",
  264. X    "small straight w/ one single",
  265. X    "three of a kind w/ two singles",
  266. X    "five singles",
  267. X    "four of a kind",
  268. X    "small straight",
  269. X    "three of a kind w/one single",
  270. X    "four singles",
  271. X    "three of a kind",
  272. X    "three singles",
  273. X    "two singles",
  274. X    "one single",
  275. X    "nothing",
  276. X    ""
  277. X};
  278. X
  279. Xmain(ac, av)
  280. Xchar   *av[];
  281. X{
  282. X    register diceset   *pd;
  283. X    register enum t_c    t;
  284. X    register int        d, singles, c, r;
  285. X    diceset                dice;
  286. X    long                cnt[(int)T_SIZE];
  287. X    long                pts[(int)T_SIZE];
  288. X    long                tpts;
  289. X    long                rolls            = ROLLS;
  290. X    boolean                aces_are_fives    = False;
  291. X    int                    haces            = 0;
  292. X    int                    held            = 0;
  293. X
  294. X    opterr = 0;
  295. X    while((c = getopt(ac, av, "jfa:h:r:")) >= 0) {
  296. X        switch(c) {
  297. X        case 'j':    /* toggle jokermode */
  298. X            jokermode = (jokermode == True) ? False : True;
  299. X            break;
  300. X        case 'f':    /* toggle aces_are_fives */
  301. X            aces_are_fives = aces_are_fives == True ? False : True;
  302. X            break;
  303. X        case 'a':    /* number of aces held */
  304. X            if((haces = atoi(optarg)) < 0 || haces >= NDICE) {
  305. X                fprintf(stderr,
  306. X                    "avg: aces must be in range 0 to %d\n", NDICE-1);
  307. X                exit(1);
  308. X            }
  309. X            break;
  310. X        case 'h':    /* number of generic dice held */
  311. X            if((held = atoi(optarg)) < 0 || held >= NDICE) {
  312. X                fprintf(stderr,
  313. X                    "avg: held must be in range 0 to %d\n", NDICE-1);
  314. X                exit(1);
  315. X            }
  316. X            break;
  317. X        case 'r':    /* number of trials */
  318. X            if((rolls = atol(optarg)) <= 0) {
  319. X                fprintf(stderr, "avg: rolls must be positive\n");
  320. X                exit(1);
  321. X            }
  322. X            break;
  323. X        default:
  324. X            fprintf(stderr,
  325. X                "usage -- avg [-j] [-r rolls] [[-f] -a aces] [-h held]\n");
  326. X            exit(1);
  327. X        }
  328. X    }
  329. X
  330. X    if(haces + held >= NDICE) {
  331. X        fprintf(stderr, "avg: aces plus held must be less than %d\n", NDICE);
  332. X        exit(1);
  333. X    }
  334. X
  335. X    /*
  336. X    **    Initialize.
  337. X    */
  338. X    irandom();
  339. X    pd = &dice;
  340. X    for(c = 0;c < (int)T_SIZE;++c)
  341. X        cnt[c] = pts[c] = 0;
  342. X
  343. X    /*
  344. X    **    Roll and tally.
  345. X    */
  346. X    for(r = 0;r < rolls;++r) {
  347. X        initdice(pd);
  348. X        if(aces_are_fives == True) {
  349. X            for(d = 0;d < haces;++d) {
  350. X                pd->d_stat[d] = Held, pd->d_comb[d] = Previous;
  351. X                pd->d_face[d] = FIVE;
  352. X            }
  353. X        } else {
  354. X            for(d = 0;d < haces;++d) {
  355. X                pd->d_stat[d] = Held, pd->d_comb[d] = Previous;
  356. X                pd->d_face[d] = ACE;
  357. X            }
  358. X        }
  359. X        for(;d < haces + held;++d) {
  360. X            pd->d_stat[d] = Held, pd->d_comb[d] = Previous;
  361. X            pd->d_face[d] = BADFACE;
  362. X        }
  363. X
  364. X        rolldice(pd);
  365. X        evaluate(pd);
  366. X
  367. X        /*
  368. X        **    Count singles.
  369. X        */
  370. X        switch(pd->d_best) {
  371. X        case All_of_a_kind:
  372. X        case Straight:
  373. X        case Asm_straight:
  374. X            singles = 0;
  375. X            break;
  376. X        default:
  377. X            for(singles = d = 0;d < NDICE;++d) {
  378. X                switch(pd->d_comb[d]) {
  379. X                case Ace:
  380. X                case Five:
  381. X                case Joker:
  382. X                    ++singles;
  383. X                    break;
  384. X                default:
  385. X                    break;
  386. X                }
  387. X            }
  388. X            break;
  389. X        }
  390. X
  391. X        /*
  392. X        **    Figure out which tallied combination this is.
  393. X        */
  394. X        switch(pd->d_best) {
  395. X        default:            continue;
  396. X        case Nothing:        t = T_ZIP; break;
  397. X        case All_of_a_kind:    t = T_AOK; break;
  398. X        case Straight:        t = T_STR; break;
  399. X        case Asm_straight:    t = T_ASMSTR; break;
  400. X        case Four_of_a_kind:t = singles ? T_4OK1S : T_4OK; break;
  401. X        case Small_straight:t = singles ? T_SMSTR1S : T_SMSTR; break;
  402. X        case Three_of_a_kind:
  403. X            switch(singles) {
  404. X            case 2: t = T_3OK2S; break;
  405. X            case 1: t = T_3OK1S; break;
  406. X            case 0: t = T_3OK; break;
  407. X            }
  408. X            break;
  409. X        case Ace:
  410. X        case Five:
  411. X        case Joker:
  412. X            switch(singles) {
  413. X            case 5:    t = T_5S; break;
  414. X            case 4:    t = T_4S; break;
  415. X            case 3:    t = T_3S; break;
  416. X            case 2:    t = T_2S; break;
  417. X            case 1:    t = T_1S; break;
  418. X            }
  419. X            break;
  420. X        }
  421. X
  422. X        /*
  423. X        **    The value of d_pts_roll is taken as the expectation value of the roll.
  424. X        **    In the case of All_of_a_kind and Asm_straight, the value must be corrected
  425. X        **    by subtracting the value of previously held dice.
  426. X        */
  427. X        scoredice(pd);
  428. X        if(t == T_AOK || t == T_ASMSTR)
  429. X            pd->d_pts_roll -= haces * (aces_are_fives==True ? P_FIVE : P_ACE);
  430. X        pts[(int)t] += pd->d_pts_roll;
  431. X        ++cnt[(int)t];
  432. X    }
  433. X
  434. X    /*
  435. X    **    Print a summary.
  436. X    */
  437. X    tpts = 0;
  438. X    printf("%-40s %6s %6s %8s\n",
  439. X        jokermode==True ? "Combination (with Jokers)" : "Combination (no Jokers)",
  440. X        "Ptsper", "Expect", "Count");
  441. X    for(c = 0;c < (int)T_SIZE;++c) {
  442. X        if(cnt[c] != 0) {
  443. X            tpts += pts[c];
  444. X            printf("%-40s %6ld %6ld %8ld\n",
  445. X                t_name[c], pts[c] / cnt[c], pts[c] / rolls, cnt[c]);
  446. X        }
  447. X    }
  448. X    printf("%-40s %6s %6ld %8ld\n", "Total", "", tpts / rolls, rolls);
  449. X
  450. X    exit(0);
  451. X}
  452. END_OF_FILE
  453. if test 5359 -ne `wc -c <'avg.c'`; then
  454.     echo shar: \"'avg.c'\" unpacked with wrong size!
  455. fi
  456. # end of 'avg.c'
  457. fi
  458. if test -f 'cubeorder.sh' -a "${1}" != "-c" ; then 
  459.   echo shar: Will not clobber existing file \"'cubeorder.sh'\"
  460. else
  461. echo shar: Extracting \"'cubeorder.sh'\" \(1021 characters\)
  462. sed "s/^X//" >'cubeorder.sh' <<'END_OF_FILE'
  463. X: ksh or sh
  464. X# vi:set sw=4 ts=4
  465. X# cubeorder: sort players in temperament/strategy order
  466. X
  467. XPATH=/bin:/usr/games
  468. X
  469. Xumask 066
  470. Xtmp=/tmp/cubeorder.$$
  471. Xtrap "rm -f $tmp;exit 1" 1 2 3 15
  472. X
  473. Xrm -f $tmp
  474. Xecho "BEGIN {" > $tmp
  475. X
  476. Xcuberank -T | awk '
  477. X    BEGIN {
  478. X        n = 1
  479. X    }
  480. X    $1 ~ /[0-9]/ {
  481. X        printf("\ttemp[%d]=\"%s\"\n", n, $2)
  482. X        printf("\tthdr[%d]=\"%s\"\n", n, $0)
  483. X        ++n;
  484. X    }
  485. X    END {
  486. X        printf("\ttemps=%d\n", n)
  487. X    }
  488. X' >> $tmp
  489. X
  490. Xcuberank -S | awk '
  491. X    BEGIN {
  492. X        n = 1
  493. X    }
  494. X    $1 ~ /[0-9]/ {
  495. X        printf("\tstrat[%d]=\"%s\"\n", n, $2)
  496. X        ++n
  497. X    }
  498. X    END {
  499. X        printf("\tstrats=%d\n", n)
  500. X    }
  501. X' >> $tmp
  502. X
  503. Xcat >> $tmp <<\ENDCAT
  504. X}
  505. X$1 !~ /[0-9]/ {
  506. X    hdr = $0
  507. X    next
  508. X}
  509. X{
  510. X    nam = substr($9, 1, 3) substr($10, 1, 3)
  511. X    if(list[nam] == "")
  512. X        list[nam] = $0
  513. X    else
  514. X        list[nam] = list[nam] "\n" $0
  515. X}
  516. XEND {
  517. X    for(t = 1;t < temps;++t) {
  518. X        print hdr
  519. X        for(s = 1;s < strats;++s) {
  520. X            nam = substr(temp[t], 1, 3) substr(strat[s], 1, 3)
  521. X            if(list[nam] != "")
  522. X                print list[nam]
  523. X        }
  524. X        print thdr[t]
  525. X        print ""
  526. X    }
  527. X}
  528. XENDCAT
  529. X
  530. Xcuberank -sP | awk -f $tmp | sed -e 's/_/ /g'
  531. X
  532. Xrm -f $tmp
  533. Xexit 0
  534. END_OF_FILE
  535. if test 1021 -ne `wc -c <'cubeorder.sh'`; then
  536.     echo shar: \"'cubeorder.sh'\" unpacked with wrong size!
  537. fi
  538. chmod +x 'cubeorder.sh'
  539. # end of 'cubeorder.sh'
  540. fi
  541. if test -f 'cuberank.6' -a "${1}" != "-c" ; then 
  542.   echo shar: Will not clobber existing file \"'cuberank.6'\"
  543. else
  544. echo shar: Extracting \"'cuberank.6'\" \(5375 characters\)
  545. sed "s/^X//" >'cuberank.6' <<'END_OF_FILE'
  546. X.TH CUBERANK 6 "cubes 5.1" GMP "UNIX Gaming Manual"
  547. X.SH NAME
  548. Xcuberank \- cubes player rankings and statistics
  549. X.\"
  550. X.\" sccsid: @(#)cuberank.6 5.1 (G.M. Paris) 89/01/22
  551. X.\"
  552. X.\"
  553. X.\"
  554. X.\"    cubes 5.1  Copyright 1988 Gregory M. Paris
  555. X.\"        Permission granted to redistribute on a no charge basis.
  556. X.\"        All other rights are reserved.
  557. X.\"
  558. X.\"
  559. X.SH SYNOPSIS
  560. X.B cuberank
  561. X[
  562. X.B \-ahlsuCLPRST
  563. X] [
  564. X.B \-n rng
  565. X[
  566. X.B \-p plr
  567. X]] [
  568. X.B \-g gms
  569. X] [
  570. X.B plr ...
  571. X]
  572. X.SH OVERVIEW
  573. XThe
  574. X.I cuberank
  575. Xprogram analyzes the
  576. X.IR cubes (6)
  577. Xscore file and prints statistics about the players.
  578. XThe various command line options allow the user
  579. Xto affect which statistics the program displays
  580. Xand which players the program provides information about.
  581. X.PP
  582. XAlthough useful in and of itself,
  583. Xcombining multiple calls of
  584. X.I cuberank
  585. Xwith pipes to
  586. X.IR sed (1)
  587. Xand/or
  588. X.IR awk (1),
  589. Xcan provide more concise summaries of player ranking information.
  590. XThe shell script /usr/games/scr provides one such summary,
  591. Xwhich can be used as is,
  592. Xor as an example for your own summary script.
  593. X.PP
  594. X.SH OUTPUT
  595. XDepending on the set of command line options specified,
  596. X.I cuberank
  597. Xwill produce from seven to twelve columns of information
  598. Xabout a selected subset of players who have played
  599. X.I cubes
  600. Xon this system.
  601. XThe columns are defined as follows.
  602. X.PP
  603. X.IP Heading 12
  604. XDescription
  605. X.IP Up
  606. Xup next number (displayed using the
  607. X.B \-u
  608. Xoption)
  609. X.IP ##
  610. Xthe player's rank (1 being the top rank)
  611. X.IP Player
  612. Xthe name of the player
  613. X.IP GP
  614. Xthe number of games played
  615. X.IP LG
  616. Xthe last game the player played in
  617. X(displayed using the
  618. X.B \-l
  619. Xoption)
  620. X.IP WinRt
  621. Xwin rate (wins / games played)
  622. X.IP GamPt
  623. Xaverage points per game (total points / games)
  624. X.IP TnPt
  625. Xaverage points per turn (sum of turn averages / games)
  626. X.IP WgtPt
  627. Xweighted points derived from
  628. X.BR WinRt ,
  629. X.BR GamPt ,
  630. Xand
  631. X.BR TnPt
  632. X.IP Pr
  633. Xthe player's game type preference:
  634. X.B \-
  635. Xfor no preference,
  636. X.B S
  637. Xfor Standard,
  638. X.B B
  639. Xfor Blitz,
  640. X.B FS
  641. Xfor Forced Standard,
  642. X.B FB
  643. Xfor Forced Blitz, and
  644. X.B ?
  645. Xfor fickle
  646. X(displayed using the
  647. X.B \-P
  648. Xoption)
  649. X.IP Tmp
  650. Xthe three character abbreviation for the player's temperament,
  651. Xwhich is the roll-or-hold decision function used by this player
  652. X(displayed using the
  653. X.B \-P
  654. Xoption)
  655. X.IP Str
  656. Xthe three character abbreviation for the player's strategy,
  657. Xwhich is the the die-discarding function used by this player
  658. X(displayed using the
  659. X.B \-P
  660. Xoption)
  661. X.PP
  662. XThe ranking order is based on the weighted point value,
  663. Xso that the player with the highest weighted point value is the
  664. Xhighest ranked player (number one).
  665. XThe weighted point value is determined using the following formula.
  666. X.IP
  667. X.B WgtPt
  668. X= 1000 *
  669. X.B WinRt
  670. X+
  671. X.B GamPt
  672. X+
  673. X.B TnPt
  674. X.PP
  675. XThe largest value in each of the
  676. X.BR WinRt ,
  677. X.BR GamPt ,
  678. X.BR TnPt ,
  679. Xand
  680. X.BR WgtPt
  681. Xcolumns is marked with an asterisk.
  682. X.SH "COMMAND LINE OPTIONS"
  683. XSeveral command line options are provided to alter the output produced by
  684. X.IR cuberank .
  685. X.IP Option 12
  686. XDescription
  687. X.IP \-a
  688. XDisplay ``ancient'' records, where ancient records are those
  689. Xcorresponding to players that haven't played a game
  690. Xin as many games as there are players in the score file.
  691. X.IP \-g\ count
  692. XTell only about players that have played in the last
  693. X.B count
  694. Xgames.
  695. X.IP \-h
  696. XProduce information about human players only.
  697. X.IP \-l
  698. XDisplay the game number of the last game each player played.
  699. X.IP \-n\ range
  700. XProduce information only about players ranked within plus or minus
  701. X.B range
  702. Xof your ranking.
  703. X.IP \-p\ plr
  704. XUse
  705. X.B plr
  706. Xas the center for the
  707. X.B \-n range
  708. Xoption.
  709. X.IP \-s
  710. XChange spaces in player names to underscores.
  711. X(Allows easier
  712. X.IR awk ing
  713. Xof
  714. X.I cuberank
  715. Xoutput.)
  716. X.IP \-u
  717. XList computer players only, in order of decreasing likelihood
  718. Xof playing in the next game.
  719. X(Due to the random factors involved,
  720. Xthere's no guarantee that players at the top of the list will be
  721. Xin the next game.)
  722. X.IP \-L
  723. XDisplay
  724. X.RB `` Lifetime ''
  725. Xvalues for
  726. X.BR WinRt ,
  727. X.BR GamPt ,
  728. X.BR TnPt ,
  729. Xand
  730. X.BR WgtPt .
  731. XThese values are representative of the complete history of games
  732. Xplayed by each player.
  733. X.IP \-R
  734. XDisplay
  735. X.RB `` Recent ''
  736. Xvalues for
  737. X.BR WinRt ,
  738. X.BR GamPt ,
  739. X.BR TnPt ,
  740. Xand
  741. X.BR WgtPt .
  742. X.B Recent
  743. Xvalues are computed using a moving average with a window of twenty-five games.
  744. XThus, these values are representative of each player's recent performance.
  745. X.IP \-C
  746. XDisplay
  747. X.RB `` Combined ''
  748. Xvalues for
  749. X.BR WinRt ,
  750. X.BR GamPt ,
  751. X.BR TnPt ,
  752. Xand
  753. X.BR WgtPt .
  754. X.B Combined
  755. Xvalues are derived from the mean of the
  756. X.B Recent
  757. Xand
  758. X.B Lifetime
  759. Xvalues.
  760. X(This is the default.)
  761. X.IP \-P
  762. XDisplay the player's ``personality.''
  763. XThis option causes the
  764. X.BR Pr ,
  765. X.BR Tmp ,
  766. Xand
  767. X.B Str
  768. Xcolumns to be produced.
  769. X.IP \-S
  770. XTabulate and display statistics for the strategies
  771. Xemployed by the players.
  772. XThe tabulated values correspond to the subset of
  773. Xplayers selected by any other command line options.
  774. X.IP \-T
  775. XTabulate and display statistics for the temperaments
  776. Xof the players.
  777. XThe tabulated values correspond to the subset of
  778. Xplayers selected by any other command line options.
  779. X.IP plr\ ...
  780. XRestrict output to that corresponding to the named players.
  781. X.PP
  782. XTwo other commonly desired options,
  783. Xto print the top or bottom of the rankings,
  784. Xare not provided,
  785. Xas they can be had as easily using the
  786. X.IR head (1)
  787. Xand
  788. X.IR tail (1)
  789. Xutilities.
  790. X.SH FILES
  791. X.ta 3.5i
  792. X.nf
  793. X/usr/games/lib/cubes.hist    the score file
  794. X/usr/games/scr    summarize cuberank script
  795. X.fi
  796. X.SH AUTHOR
  797. XGreg Paris <gmp@rayssd.ray.com>
  798. X.SH "SEE ALSO"
  799. Xcubes(6), awk(1), head(1), sed(1), tail(1)
  800. END_OF_FILE
  801. if test 5375 -ne `wc -c <'cuberank.6'`; then
  802.     echo shar: \"'cuberank.6'\" unpacked with wrong size!
  803. fi
  804. # end of 'cuberank.6'
  805. fi
  806. if test -f 'cubes.h' -a "${1}" != "-c" ; then 
  807.   echo shar: Will not clobber existing file \"'cubes.h'\"
  808. else
  809. echo shar: Extracting \"'cubes.h'\" \(12208 characters\)
  810. sed "s/^X//" >'cubes.h' <<'END_OF_FILE'
  811. X/* vi:set sw=4 ts=4: */
  812. X/*
  813. X**    sccsid: @(#)cubes.h 5.1 (G.M. Paris) 89/01/22
  814. X*/
  815. X
  816. X/*
  817. X**
  818. X**    cubes 5.1  Copyright 1989 Gregory M. Paris
  819. X**        Permission granted to redistribute on a no charge basis.
  820. X**        All other rights are reserved.
  821. X**
  822. X*/
  823. X
  824. X/*
  825. X**    If you don't want Four_of_a_kind or Small_straight, then comment these out.
  826. X**    Unfortunately, you'll have to recalculate the values in risktbl[] if you do.
  827. X**    The existence of Jokers is controlled by a cubeserver command line option.
  828. X*/
  829. X#define    FOUR        4        /* how many in a four of a kind (if defined) */
  830. X#define    SMSTR        4        /* number of dice in small straight (if def) */
  831. X#define    ASMSTR        5        /* number of dice in assembled straight (if def) */
  832. X
  833. X/*
  834. X**    Although you could change any of the following parameters, the nature of
  835. X**    the game would be altered.  Also, some things like 5o'kind are hard coded
  836. X**    in places and would not change automatically.  Best to leave be.
  837. X*/
  838. X#define    SIDES        6        /* six sided dice */
  839. X#define    NDICE        5        /* number of dice in set */
  840. X#define    ONBOARD        500        /* turn score needed to get on scoreboard */
  841. X#define    OFFBOARD    500        /* turn score needed to cross WINSCORE thresh */
  842. X#define    WINSCORE    10000    /* minimum score needed to win in Standard game */
  843. X#define    BLITZSCORE    7500    /* minimum score needed to win in Blitz game */
  844. X#define    WINMARGIN    250        /* winner must best others by this margin */
  845. X
  846. X/*
  847. X**    These values are the basis for scoring.  Again, if you change them, the
  848. X**    play of the game will be altered.  Leave them as they are.
  849. X*/
  850. X#define    P_ACEMULT    10        /* ace is worth disproportionate amount */
  851. X#define    P_AOKMULT    300        /* multiplier for all of a kind */
  852. X#define    P_STRAIGHT    1500    /* points for straight */
  853. X#define    P_ASMSTR    750        /* points for assembled straight */
  854. X#define    P_4OKMULT    200        /* multiplier for three of a kind */
  855. X#define    P_SMSTR        400        /* points for a small straight */
  856. X#define    P_3OKMULT    100        /* multiplier for three of a kind */
  857. X#define    P_ACE        100        /* points for single ace */
  858. X#define    P_FIVE        50        /* points for single five */
  859. X#define    P_JOKER        0        /* value of single Jokers */
  860. X#define    P_JOKERMULT    30        /* <n>o'kind multiplier for Jokers */
  861. X
  862. X/*
  863. X**    The following defines are just symbolic values for numbers.
  864. X*/
  865. X#define    BADFACE        0        /* impossible die face */
  866. X#define    ACE            1        /* an ACE is a one, a scoring die */
  867. X#define    DEUCE        2        /* an DEUCE is a two, the most worthless die */
  868. X#define    THREE        3        /* how many in a Three_of_a_kind or the face name */
  869. X#define    FIVE        5        /* FIVE is five, a scoring die */
  870. X#define    JOKER        9        /* an imphysical die face and scoring die */
  871. X#define    MESGLEN        128        /* length of message buffer */
  872. X#define    NAMELEN        64        /* player name buffer length */
  873. X#define    IDLEN        64        /* player identity buffer length */
  874. X#define    DISPLEN        18        /* field width in client name display */
  875. X#define    COMP        0        /* computer starts as player zero */
  876. X#define    PLAYERS        10        /* max players (client score window limits) */
  877. X#define    MINPLR        4        /* min players at game begining */
  878. X#define    MINCOMP        2        /* min computers at game beginning */
  879. X#define    WRITETIMO    20        /* timeout on socket writes */
  880. X#define    READTIMO    60        /* timeout on socket reads */
  881. X#define    MAXTIMO        3        /* too many timeouts -- goodbye! */
  882. X
  883. X/*
  884. X**    The ANCIENT value is used to prune old records from the history.
  885. X**    The two credit values give additional grace to players as a multiplier
  886. X**    of the number of games played.
  887. X*/
  888. X#define    ANCIENT        ((long)(nhist + 1))    /* depends on number of players */
  889. X#define    ANALCREDIT    0                    /* games played credit in histanal */
  890. X#define    WRITECREDIT    5                    /* games played credit in histwrite */
  891. X
  892. X/*
  893. X**    To mark asynchronous requests, we prepend each with ASYNCMARK.
  894. X**    It should not be a character that would normally be typed.
  895. X*/
  896. X#define    ASYNCMARK    '\1'        /* control-A */
  897. X
  898. X/*
  899. X**    Message numbers.  Defined as enum so that we can keep them
  900. X**    sequential without much trouble.  This allows the dispatching
  901. X**    function in the client to be faster, since we can avoid doing
  902. X**    a linear search of the action table by using a function array.
  903. XXXX    We assume that enums are ints for use in sprintf() calls.
  904. X*/
  905. X#define    M_BASE    100        /* lowest message number */
  906. Xtypedef enum {
  907. X    M_NOOP = M_BASE,    /* no operation (usually heartbeat) */
  908. X    M_INFO,                /* informational or status messages */
  909. X    M_HELP,                /* help messages */
  910. X    M_DICE,                /* complete dice status */
  911. X    M_PARM,                /* game parameters */
  912. X    M_PLAY,                /* play-by-play on other players */
  913. X    M_HELO,                /* hello message */
  914. X    M_DOWN,                /* shutdown message */
  915. X    M_RQID,                /* id request */
  916. X    M_WORP,                /* watch or play? */
  917. X    M_SORP,                /* wait (spider) or play? */
  918. X    M_ACTV,                /* you are an active player */
  919. X    M_AUTO,                /* you are on autopilot */
  920. X    M_WAIT,                /* you are waiting to be added */
  921. X    M_VOYR,                /* you are now a voyeur */
  922. X    M_SPDR,                /* you are now a spider */
  923. X    M_TURN,                /* Player %d, ... up with %d points. */
  924. X    M_NWIN,                /* game over, no winner */
  925. X    M_OVER,                /* Player %d has won the game! */
  926. X    M_RANK,                /* player rank at end of game */
  927. X    M_CPLR,                /* clear all players */
  928. X    M_UARE,                /* you are player %d */
  929. X    M_PNUM,                /* player %d %s */
  930. X    M_FARE,                /* farewell %d %s */
  931. X    M_NOBS,                /* %d observer[s] */
  932. X    M_MSCO,                /* You now have %d points. */
  933. X    M_OSCO,                /* Player %d now has %d points. */
  934. X    M_ANOG,                /* play another game? */
  935. X    M_RFST,                /* Ready to roll? */
  936. X    M_KEEP,                /* %d points: */
  937. X    M_ARGE,                /* argument error */        
  938. X    M_BADM                /* bad message */
  939. X} m_num;
  940. X#define    M_LAST    (int)M_BADM        /* highest message number */
  941. X
  942. X/*
  943. X**    Definitions for status queries.  For now, only one query
  944. X**    type, and only two status responses are supported.
  945. X*/
  946. X#define    STATLEN        512        /* max length of status response */
  947. X#define    Q_ROSTER    '\1'    /* query: current player roster */
  948. X#define    S_IDLE        '\1'    /* status: idle */
  949. X#define    S_ROSTER    '\2'    /* status: current player roster */
  950. X#define    S_UNRECOG    '\177'    /* status: unrecognized query */
  951. X
  952. X/*
  953. X**    Some stuff for converting numbers to names.  Probably should be elsewhere.
  954. X*/
  955. Xextern char       *numnames[][2];
  956. X#define    NUMBER(n)            (numnames[n][0])
  957. X#ifdef    lint
  958. X#define    FACE(show,ndice)    (numnames[show][ndice])    /* fake to shut up lint */
  959. X#else    lint
  960. X#define    FACE(show,ndice)    (numnames[show][(ndice)!=1])
  961. X#endif    lint
  962. X
  963. X/*
  964. X**    boolean: remind me never to do this again
  965. X*/
  966. Xtypedef enum { False, True } boolean;
  967. X
  968. X/*
  969. X**    diestat: the four states a die can be in
  970. X*/
  971. Xtypedef enum { Free, Held, Rolled, Taken } diestat;
  972. X
  973. X/*
  974. X**    combination: names for all scoring combinations
  975. X*/
  976. Xtypedef enum {
  977. X    Previous = -1, Nothing, Joker, Five, Ace, Three_of_a_kind,
  978. X    Small_straight, Four_of_a_kind, Asm_straight, Straight, All_of_a_kind
  979. X} combination;
  980. X
  981. X/*
  982. X**    Currently, defining DESC does nothing useful.
  983. X*/
  984. X/*#define    DESC    1        /* scoring description (future use) */
  985. X
  986. X#ifdef    DESC
  987. X/*
  988. X**    scoredesc: complete description of a scoring combination
  989. X*/
  990. Xtypedef struct {
  991. X    combination    sc_comb;    /* the type of combination */
  992. X    short        sc_num;        /* how many of this combination */
  993. X    short        sc_face;    /* face value for N_of_a_kind */
  994. X} scoredesc;
  995. X#endif    DESC
  996. X
  997. X/*
  998. X**    diceset: structure for tracking status of all dice
  999. X*/
  1000. Xtypedef struct {
  1001. X    int            d_face[NDICE];        /* number showing on each die */
  1002. X    diestat        d_stat[NDICE];        /* status of each die */
  1003. X    combination    d_comb[NDICE];        /* die's scoring combination */
  1004. X#ifdef    DESC
  1005. X    scoredesc    d_desc[NDICE];        /* list of combinations scored */
  1006. X#endif    DESC
  1007. X    combination    d_best;                /* best combination scored */
  1008. X    boolean        d_again;            /* true if rolling again */
  1009. X    int            d_rolling;            /* number of dice rolling */
  1010. X    int            d_pts_roll;            /* points due to last roll */
  1011. X    int            d_pts_dice;            /* points by this set of NDICE */
  1012. X    int            d_pts_turn;            /* points accumulated this turn */
  1013. X    int            d_pts_max;            /* max points showing this turn */
  1014. X    char        d_mesg[MESGLEN];    /* status message */
  1015. X} diceset;
  1016. X
  1017. X/*
  1018. X**    winpref: player game type preference
  1019. X*/
  1020. Xtypedef enum {
  1021. X    Nopref,                            /* don't care */
  1022. X    Standard,                        /* game to WINSCORE */
  1023. X    Blitz,                            /* game to BLITZSCORE */
  1024. X    Fickle,                            /* for computer use */
  1025. X    Fstand,                            /* Standard or quit */
  1026. X    Fblitz,                            /* Blitz or quit */
  1027. X} winpref;
  1028. X
  1029. X/*
  1030. X**    blitzmode: when the server will play Blitz games
  1031. X*/
  1032. Xtypedef enum {
  1033. X    Noblitz,                        /* never to be played */
  1034. X    Onrequest,                        /* only when requested */
  1035. X    Workhours,                        /* default during working hours */
  1036. X    Enforced,                        /* enforced during working hours */
  1037. X} blitzmode;
  1038. X
  1039. X/*
  1040. X**    cstat: player/connection status
  1041. X*/
  1042. Xtypedef enum {
  1043. X    Inactive,    /* no player */
  1044. X    Watching,    /* human voyeur */
  1045. X    Waiting,    /* human waiting to get in */
  1046. X    Spider,        /* human waiting for another human */
  1047. X    Active,        /* active human player */
  1048. X    Computer,    /* active computer player */
  1049. X} cstat;
  1050. X
  1051. X/*
  1052. X**    strategy: description of a computer player strategy
  1053. X*/
  1054. Xtypedef struct    {
  1055. X    int          (*s_func)();            /* strategy function */
  1056. X    char       *s_name;                /* name of strategy */
  1057. X} strategy;
  1058. X
  1059. X/*
  1060. X**    temper: description of a computer player temperament
  1061. X*/
  1062. Xtypedef struct    {
  1063. X    boolean      (*t_func)();            /* temperament function */
  1064. X    char       *t_name;                /* name of temperament */
  1065. X} temper;
  1066. X
  1067. X/*
  1068. X**    computer: complete description of a computer player
  1069. X*/
  1070. Xtypedef struct    {
  1071. X    char       *c_name;                /* computer player name */
  1072. X    strategy   *c_strategy;            /* pointer into strategy table */
  1073. X    temper     *c_temper;            /* pointer into temperament table */
  1074. X    winpref        c_pref;                /* gametype preference */
  1075. X} computer;
  1076. X
  1077. X/*
  1078. X**    player: player/connection status
  1079. X*/
  1080. Xtypedef struct {
  1081. X    cstat        p_stat;                /* connection status */
  1082. X    int            p_fd;                /* communications socket */
  1083. X    int            p_timeouts;            /* number of timeouts */
  1084. X    int            p_score;            /* player score */
  1085. X    int            p_squander;            /* points rolled away */
  1086. X    int            p_mood;                /* computer mood value */
  1087. X    winpref        p_pref;                /* winscore preference */
  1088. X    boolean        p_onboard;            /* True if player on board */
  1089. X    computer   *p_computer;            /* pointer into computer table */
  1090. X    char        p_name[NAMELEN];    /* player name */
  1091. X    char        p_id[IDLEN];        /* "unique" player id */
  1092. X} player;
  1093. X
  1094. X/*
  1095. X**    Computer moods have no meaning other than that defined
  1096. X**    by each temperament that uses the p_mood value.
  1097. X*/
  1098. X#define    NOMOOD    0    /* no mood selected */
  1099. X#define    MAXMOOD    5    /* moods 1 through MAXMOOD */
  1100. X
  1101. X/*
  1102. X**    graphtype: type of graphics the terminal supports
  1103. X*/
  1104. Xtypedef enum    {
  1105. X    Nographics, Digital, Zenith,
  1106. X} graphtype;
  1107. X
  1108. X/*
  1109. X**    history: player scoring history
  1110. X*/
  1111. X#define    H_MVWINMULT        10000L        /* to avoid floating point stuff */
  1112. Xtypedef struct    {
  1113. X    long        h_points;            /* lifetime total number of points */
  1114. X    long        h_avgturn;            /* lifetime average points per turn */
  1115. X    long        h_wins;                /* lifetime number of games won */
  1116. X    long        h_games;            /* lifetime number of games played */
  1117. X    long        h_mvpoints;            /* moving sum of game points */
  1118. X    long        h_mvavgturn;        /* moving sum of avg points per turn */
  1119. X    long        h_mvwins;            /* mov sum of games won times H_MVWINMULT */
  1120. X    long        h_mvgames;            /* games used to calculate h_mv values */
  1121. X    long        h_lastgame;            /* last game played in */
  1122. X    long        h_weight;            /* weighted value of record */
  1123. X    long        h_rank;                /* ranking based on weight */
  1124. X    computer   *h_computer;            /* pointer into computer table */
  1125. X    char        h_id[IDLEN];        /* "unique" player id */
  1126. X} history;
  1127. X
  1128. X/*
  1129. X**    ptstype: history points type
  1130. X*/
  1131. Xtypedef enum { Lifetime, Recent, Combined } ptstype;
  1132. X
  1133. X/*
  1134. X**    risk: rolling risks/expectations
  1135. X*/
  1136. Xtypedef struct    {
  1137. X    double    r_p_any;    /* probability of scoring anything (assumes mix) */
  1138. X    double    r_p_all;    /* probability of scoring all (assumes mix) */
  1139. X    double    r_p_aok;    /* prob. of completing All_of_a_kind in non-scoring */
  1140. X    int        r_e_mix;    /* <rolled> with a mix of held dice */
  1141. X    int        r_e_aces;    /* <rolled> with held dice all aces (no 3o'kind) */
  1142. X    int        r_e_fives;    /* <rolled> with held dice all fives (no 3o'kind) */
  1143. X    int        r_e_jokers;    /* <rolled> with held dice all jokers (no 3o'kind) */
  1144. X} risk;
  1145. X
  1146. X/*
  1147. X**    enterlate: what to do about a game in progress or about waiting
  1148. X*/
  1149. Xtypedef enum {
  1150. X    Ask, Watch, Play, Wait
  1151. X} enterlate;
  1152. X
  1153. X/*
  1154. X**    Definitions for convenient use of select().
  1155. X*/
  1156. X#ifndef    FD_ZERO
  1157. X/*
  1158. XXXX:    This system is missing the FD_ macros for select, so it's
  1159. XXXX:    probably a 4.2BSDish system.  That means that the fd_set
  1160. XXXX:    type is probably just a single int, so just fake it here.
  1161. X*/
  1162. X#define    FD_ZERO(p)        ((p)->fds_bits[0] = 0)
  1163. X#define    FD_SET(n,p)        ((p)->fds_bits[0] |= 1L << (n))
  1164. X#define    FD_ISSET(n,p)    (((p)->fds_bits[0] & (1L << (n))) != 0)
  1165. X#endif    FD_ZERO
  1166. X#define    NOSEL        ((fd_set *)0)
  1167. X#define    HANG        ((struct timeval *)0)
  1168. END_OF_FILE
  1169. if test 12208 -ne `wc -c <'cubes.h'`; then
  1170.     echo shar: \"'cubes.h'\" unpacked with wrong size!
  1171. fi
  1172. # end of 'cubes.h'
  1173. fi
  1174. if test -f 'cubeserver.6' -a "${1}" != "-c" ; then 
  1175.   echo shar: Will not clobber existing file \"'cubeserver.6'\"
  1176. else
  1177. echo shar: Extracting \"'cubeserver.6'\" \(5480 characters\)
  1178. sed "s/^X//" >'cubeserver.6' <<'END_OF_FILE'
  1179. X.TH CUBESERVER 6 "cubes 5.1" GMP "UNIX Gaming Manual"
  1180. X.SH NAME
  1181. Xcubeserver \- cubes dice game service
  1182. X.\"
  1183. X.\" sccsid: @(#)cubeserver.6 5.1 (G.M. Paris) 89/01/22
  1184. X.\"
  1185. X.\"
  1186. X.\"
  1187. X.\"    cubes 5.1  Copyright 1988 Gregory M. Paris
  1188. X.\"        Permission granted to redistribute on a no charge basis.
  1189. X.\"        All other rights are reserved.
  1190. X.\"
  1191. X.\"
  1192. X.SH SYNOPSIS
  1193. X.B cubeserver
  1194. X[
  1195. X.B \-j
  1196. X] [
  1197. X.BR \-b { nrwe }
  1198. X]
  1199. X.SH OVERVIEW
  1200. XThe
  1201. X.I cubeserver
  1202. Xis the program that provides the
  1203. X.IR cubes
  1204. Xgame service.
  1205. XThis manual page is intended for games administrators.
  1206. XPotential
  1207. X.I cubes
  1208. Xplayers should see the manual pages for
  1209. X.IR cubes ,
  1210. X.IR cuberank ,
  1211. Xand
  1212. X.IR cubestat
  1213. Xto find out how to play the game.
  1214. X.SH "FILE MODES AND OWNERSHIPS"
  1215. XThe
  1216. X.I cubeserver
  1217. Xis meant to be run setuid to an unprivileged daemon account, often
  1218. X.IR gdaemon .
  1219. XThe files used by the
  1220. X.I cubeserver
  1221. Xare assumed to exist, have the same ownership as the executable,
  1222. Xand have permissions mode of 644, 640, or 600.
  1223. XThe Makefile supplied with the
  1224. X.I cubes
  1225. Xdistribution should create all needed files with appropriate
  1226. Xownership and permissions.
  1227. X.SH "UNIX DOMAIN CUBES SERVICE"
  1228. XThe
  1229. X.I cubeserver
  1230. Xcan be configured to provide
  1231. X.I cubes
  1232. Xservice in the
  1233. X.B UNIX
  1234. Xdomain.
  1235. XThis service can be provided in addition to,
  1236. Xor as an alternative to the
  1237. X.B INET
  1238. Xdomain service (described below).
  1239. XAt least one of the services must be provided,
  1240. Xor the server will not run.
  1241. X.PP
  1242. XThe
  1243. X.B UNIX
  1244. Xdomain service allows connections from clients only on the local system,
  1245. Xand could possibly be more efficient than the
  1246. X.B INET
  1247. Xservice.
  1248. XTo configure the server to provide service in this domain,
  1249. Xit must be compiled with the
  1250. X.B \-DUNIXSOCK=pathname
  1251. Xoption, where
  1252. X.B pathname
  1253. Xis the name of the rendezvous socket.
  1254. X(The client program also must be compiled with this option.)
  1255. X.SH "INET DOMAIN CUBES SERVICE"
  1256. XThe
  1257. X.I cubeserver
  1258. Xcan be configured to provide
  1259. X.I cubes
  1260. Xservice in the
  1261. X.B INET
  1262. Xdomain,
  1263. Xallowing the server to be accessed from remote systems.
  1264. XTo provide this networked service,
  1265. Xthe server must be compiled with the
  1266. X.B \-DINETSOCK
  1267. Xoption and the
  1268. X.I cubes
  1269. Xservice must be made a ``well known'' service.
  1270. X.PP
  1271. XMaking the
  1272. X.I cubes
  1273. Xservice well known
  1274. Xusually means adding an entry to the file /etc/services
  1275. X(see
  1276. X.IR services (5)).
  1277. X(Note that the entry should be added to the services file on every
  1278. Xsystem upon which the client program,
  1279. X.IR cubes ,
  1280. Xis to be run, not just on the system on which the server is to be run.)\ 
  1281. XThe entry is for the TCP socket that the server uses to communicate
  1282. Xwith its clients during game play.
  1283. XThe port number chosen must be greater than 1024
  1284. Xso that the server can run as an unprivileged user.
  1285. XAlthough not officially registered in any way,
  1286. Xthe following entry is suggested.
  1287. X.PP
  1288. X.DT
  1289. X.nf
  1290. X.ft B
  1291. X    cube        3840/tcp    cubes
  1292. X.fi
  1293. X.ft P
  1294. X.SH "CUBES STATUS SERVICE"
  1295. XIf another well known service is defined, namely the
  1296. X.I cubestat
  1297. Xservice, the server will listen on an
  1298. X.B INET
  1299. Xdomain UDP socket for status requests generated by the
  1300. X.I cubestat
  1301. Xprogram.
  1302. XSince the TCP and UDP port number spaces are separate,
  1303. Xit is reasonable to use the same port number for both sockets.
  1304. X(Remember, the port number chosen must be greater than 1024
  1305. Xso that the server can run as an unprivileged user.)\ 
  1306. XAgain, though not officially registered in any way,
  1307. Xthe following entry is suggested.
  1308. X.PP
  1309. X.DT
  1310. X.nf
  1311. X.ft B
  1312. X    cubestat    3840/udp    cubestatus
  1313. X.fi
  1314. X.ft P
  1315. X.PP
  1316. XThe current version of the server does not provide status service in the
  1317. X.B UNIX
  1318. Xdomain, regardless of compile time options.
  1319. X.SH "STARTING THE SERVER"
  1320. XNormally, the
  1321. X.I cubeserver
  1322. Xwill be started automatically on system boot
  1323. Xby placing the appropriate line in the file /etc/rc.local,
  1324. Xor possibly in another file where similar daemons are started.
  1325. XAlternatively, it is possible to start the server via a program like
  1326. X.IR cron .
  1327. XFor this purpose,
  1328. Xwhen the server is started
  1329. Xit prints its process id on the standard output.
  1330. XThis pid could be saved in a file and be used to turn the daemon
  1331. Xoff at a later time,
  1332. Xagain using
  1333. X.IR cron .
  1334. XTo kill the server immediately,
  1335. Xsend it a SIGTERM.
  1336. XMore politely, killing the server with SIGHUP
  1337. Xcauses it to exit when any game in progress finishes.
  1338. X.PP
  1339. XThere are two command line options for
  1340. X.IR cubeserver .
  1341. X.PP
  1342. XThe
  1343. X.B \-j
  1344. Xoption allows the server to occasionally play the game of
  1345. X.I cubes
  1346. Xwith dice that have jokers on them.
  1347. XWithout this option,
  1348. Xthe game is always played with normal six-sided dice.
  1349. X.PP
  1350. XThe
  1351. X.BR \-b < when >
  1352. Xoption allows specifying when the server will play the game of
  1353. X.I cubes
  1354. Xin Blitz mode (games end at 7500 rather than 10000 points).
  1355. XThe values of
  1356. X.RB ` n ',
  1357. X.RB ` r ',
  1358. X.RB ` w ',
  1359. Xand
  1360. X.RB ` e '
  1361. Xtell the server to play in Blitz mode
  1362. Xnever, on request, default during working hours,
  1363. Xand enforced during working hours respectively.
  1364. XThe default is
  1365. X.RB ` e '.
  1366. X.SH FILES
  1367. X.ta 3.2i
  1368. X.nf
  1369. X/usr/games/lib/cubeserver    the cubeserver executable
  1370. X/usr/games/lib/cubes.hist    the cubes score file
  1371. X/usr/games/lib/cubes.monikers    names for the chamelion
  1372. X.fi
  1373. X.PP
  1374. XThe cubes.monikers file is a record of names selected by
  1375. Xhuman players for use by the chamelion player.
  1376. XThis file will grow without bound,
  1377. Xso it might be a good idea to check it on occasion.
  1378. XA good idea anyway, since
  1379. X.I cubeserver
  1380. Xdoes not judge the acceptability of names before using them.
  1381. XThe program has a short list of names compiled in,
  1382. Xso you can avoid problems with this file by linking it to /dev/null.
  1383. X.DT
  1384. X.SH "SEE ALSO"
  1385. Xcubes(6), cuberank(6), cubestat(6), services(5), rc(8), cron(8)
  1386. X.SH AUTHOR
  1387. XGreg Paris <gmp@rayssd.ray.com>
  1388. END_OF_FILE
  1389. if test 5480 -ne `wc -c <'cubeserver.6'`; then
  1390.     echo shar: \"'cubeserver.6'\" unpacked with wrong size!
  1391. fi
  1392. # end of 'cubeserver.6'
  1393. fi
  1394. if test -f 'histconv.sh' -a "${1}" != "-c" ; then 
  1395.   echo shar: Will not clobber existing file \"'histconv.sh'\"
  1396. else
  1397. echo shar: Extracting \"'histconv.sh'\" \(774 characters\)
  1398. sed "s/^X//" >'histconv.sh' <<'END_OF_FILE'
  1399. X#! /bin/sh
  1400. X#
  1401. X#  This script is for converting cubes4.1 style history file to cubes5.1 style.
  1402. X#  You must use this script if you were running cubes4.1 and wish to keep
  1403. X#  the players' records intact.
  1404. X#
  1405. Xawk '
  1406. XBEGIN {
  1407. X    MVGAMES = 25;
  1408. X}
  1409. X{
  1410. X    split($1, x, ";"); games=x[1]; lastgame=x[2];
  1411. X    if(games == 0) next;
  1412. X    if(games < MVGAMES) mvgames = games;
  1413. X    else mvgames = MVGAMES;
  1414. X
  1415. X    wins=$2; points=$3; avgturn=$4;
  1416. X
  1417. X    name=$5;
  1418. X    for(n = 6;n <= NF;++n)
  1419. X        name = name " " $n;
  1420. X
  1421. X    mvwins = (10000 * wins * mvgames) / games;
  1422. X    mvpoints = (points * mvgames) / games;
  1423. X    mvavgturn = (avgturn * mvgames) / games;
  1424. X
  1425. X    printf("L %5d %5d %10d %10d %6d %s\n", games, wins, points, avgturn, lastgame, name);
  1426. X    printf("M %5d %5d %10d %10d %6d %s\n", mvgames, mvwins, mvpoints, mvavgturn, lastgame, name);
  1427. X}
  1428. X' $1
  1429. END_OF_FILE
  1430. if test 774 -ne `wc -c <'histconv.sh'`; then
  1431.     echo shar: \"'histconv.sh'\" unpacked with wrong size!
  1432. fi
  1433. chmod +x 'histconv.sh'
  1434. # end of 'histconv.sh'
  1435. fi
  1436. if test -f 'random.c' -a "${1}" != "-c" ; then 
  1437.   echo shar: Will not clobber existing file \"'random.c'\"
  1438. else
  1439. echo shar: Extracting \"'random.c'\" \(3095 characters\)
  1440. sed "s/^X//" >'random.c' <<'END_OF_FILE'
  1441. X/*    vi:set sw=4 ts=4: */
  1442. X#ifndef    lint
  1443. Xstatic char    sccsid[] = "@(#)random.c 5.1 (G.M. Paris) 89/01/22";
  1444. X#endif    lint
  1445. X
  1446. X/*
  1447. X**
  1448. X**    cubes 5.1  Copyright 1989 Gregory M. Paris
  1449. X**        Permission granted to redistribute on a no charge basis.
  1450. X**        All other rights are reserved.
  1451. X**
  1452. X*/
  1453. X
  1454. X#include    <sys/types.h>
  1455. X#include    <sys/time.h>
  1456. X#include    "cubes.h"
  1457. X
  1458. Xextern boolean    jokermode;
  1459. Xextern char       *initstate();
  1460. Xextern long        random();
  1461. Xextern time_t    time();
  1462. X
  1463. Xstatic long        diestate[3][256 / sizeof(long)];    /* for die rolls */
  1464. Xstatic long        numstate[256 / sizeof(long)];        /* for random numbers */
  1465. X
  1466. X#define    RANDOM()    (int)((unsigned)random() >> 1)    /* XXX: ensure non-neg? */
  1467. X
  1468. X/*
  1469. X**    irandom: initialize random number generators
  1470. X*/
  1471. Xirandom()
  1472. X{
  1473. X    struct timeval        tv;
  1474. X    struct timezone        tz;
  1475. X    register unsigned    n;
  1476. X    int                    nstate    = 0;
  1477. X
  1478. X    /*
  1479. X    **    Initialize first die rolling state.
  1480. X    */
  1481. X    (void) gettimeofday(&tv, &tz);
  1482. X    n = (tv.tv_sec << 8) + ((unsigned)tv.tv_usec >> 8);
  1483. X    (void) initstate(n, diestate[nstate++], sizeof diestate[0]);
  1484. X    for(n %= 49;n != 0;--n)
  1485. X        (void) random();
  1486. X    
  1487. X    /*
  1488. X    **    Initialize random number state and second die rolling state.
  1489. X    */
  1490. X    (void) gettimeofday(&tv, &tz);
  1491. X    n = ((tv.tv_sec << 16) | ((unsigned)tv.tv_usec >> 16)) + getpid();
  1492. X    (void) initstate(n, numstate, sizeof numstate);
  1493. X    for(n %= 17;n != 0;--n)
  1494. X        (void) random();
  1495. X    n = (unsigned)(random() + 1);    /* using numstate */
  1496. X    (void) initstate(n, diestate[nstate++], sizeof diestate[0]);
  1497. X    for(n %= 13;n != 0;--n)
  1498. X        (void) random();
  1499. X
  1500. X    /*
  1501. X    **    Initialize third die rolling state.
  1502. X    */
  1503. X    (void) gettimeofday(&tv, &tz);
  1504. X    n = (tv.tv_sec << 4) ^ ((unsigned)tv.tv_usec >> 4);
  1505. X    (void) initstate(n, diestate[nstate++], sizeof diestate[0]);
  1506. X    for(n %= 27;n != 0;--n)
  1507. X        (void) random();
  1508. X}
  1509. X
  1510. X/*
  1511. X**    dieroll:
  1512. X**        if jokermode is true
  1513. X**            roll a trick six-sided die which may show a JOKER on
  1514. X**            any face every once in thirteen rolls
  1515. X**        else
  1516. X**            roll a regular six-sided die
  1517. X*/
  1518. Xdieroll()
  1519. X{
  1520. X    static which    = 0;
  1521. X
  1522. X#define    THIRTEEN    (2 * SIDES + 1)
  1523. X
  1524. X    /*
  1525. X    **    We use three random number states for the dice because it turns out
  1526. X    **    that the RNG is not good for producing random *strings* of numbers.
  1527. X    **    This method does seem to increase randomness for the combinations
  1528. X    **    involving three to five dice.  Maybe we should use NDICE states,
  1529. X    **    but how do we ensure that our seeds are different enough?
  1530. X    */
  1531. X    (void) setstate(diestate[which++ % 3]);
  1532. X
  1533. X    if(jokermode == True) {
  1534. X        int        s;
  1535. X
  1536. X        if((s = RANDOM() % THIRTEEN) == THIRTEEN - 1)
  1537. X            return JOKER;
  1538. X        return s % SIDES + 1;
  1539. X    }
  1540. X
  1541. X    return RANDOM() % SIDES + 1;
  1542. X
  1543. X#undef    THIRTEEN
  1544. X}
  1545. X
  1546. X/*
  1547. X**    randint: return a random integer from 1 to n
  1548. X*/
  1549. Xrandint(n)
  1550. X{
  1551. X    if(n <= 1)
  1552. X        return 1;
  1553. X    (void) setstate(numstate);
  1554. X    return RANDOM() % n + 1;
  1555. X}
  1556. X
  1557. X/*
  1558. X**    hesitate: random hesitation in the range minv to maxv milliseconds
  1559. XXXX        No checking of arguments is done.
  1560. X*/
  1561. Xhesitate(minv, maxv)
  1562. Xlong    minv, maxv;
  1563. X{
  1564. X    long            diff, t;
  1565. X    struct timeval    tv;
  1566. X
  1567. X    if((diff = maxv - minv) <= 1)
  1568. X        t = minv;
  1569. X    else {
  1570. X        (void) setstate(numstate);
  1571. X        t = random() % diff + minv;
  1572. X    }
  1573. X
  1574. X    tv.tv_sec = t / 1000;
  1575. X    tv.tv_usec = (t % 1000) * 1000;
  1576. X    (void) select(32, NOSEL, NOSEL, NOSEL, &tv);
  1577. X}
  1578. END_OF_FILE
  1579. if test 3095 -ne `wc -c <'random.c'`; then
  1580.     echo shar: \"'random.c'\" unpacked with wrong size!
  1581. fi
  1582. # end of 'random.c'
  1583. fi
  1584. echo shar: End of archive 8 \(of 8\).
  1585. cp /dev/null ark8isdone
  1586. MISSING=""
  1587. for I in 1 2 3 4 5 6 7 8 ; do
  1588.     if test ! -f ark${I}isdone ; then
  1589.     MISSING="${MISSING} ${I}"
  1590.     fi
  1591. done
  1592. if test "${MISSING}" = "" ; then
  1593.     echo You have unpacked all 8 archives.
  1594.     rm -f ark[1-9]isdone
  1595. else
  1596.     echo You still need to unpack the following archives:
  1597.     echo "        " ${MISSING}
  1598. fi
  1599. ##  End of shell archive.
  1600. exit 0
  1601.